    <!-- Advance table -->
    <script src="<?=$url_styles?>js/plugins/tables/jquery.dataTables.min.js"></script>
    <script src="<?=$url_styles?>js/plugins/tables/colResizable-1.3.min.js"></script>
    <script src="<?=$url_styles?>js/plugins/tables/jquery.tablesorter.min.js"></script> 
    
    <script src="<?=$url_styles?>js/plugins/formselements/jquery.ibutton.min.js"></script>  
    <script src="<?=$url_styles?>js/plugins/formselements/ui.spinner.min.js"></script> 
    <script>
		var page=1;
        function load_table()
        {
            $.ajax({
               url: '<?=url_create('admin','catalogue','read')?>',
               dataType: 'json',
               type: 'post',
               success: function(o)
               {
                   if(o.state=='success'){
                       var str='';
                       for(var i =0;i<o.data.length;i++){
                           var r=o.data[i];
						   var row_class = (o.data[i].name==null || o.data[i].name=='')?'X':'A';
						   if(i%2==1) row_class+=" odd";
						   else row_class+=" even";
						   if(o.data[i].main==1) row_class='C';
						   var type_name=''
						   if(r.type==0) type_name='<?=lang('catalogue_topic')?>'
						   if(r.type==1) type_name='<?=lang('catalogue_product')?>'
						   if(r.type==2) type_name='<?=lang('catalogue_link')?>'
                           str+='<tr id="row_'+r.id+'" class="grade'+row_class+'">'+
                                  '<td>'+r.pre+r.name+'</td>'+
								  '<td>'+type_name+'</td>'+
								  '<td>'+r.menu+'</td>'+
								  '<td>'+r.home+'</td>'+
                                  '<td class="center"><a href="#user_modal" data="'+r.id+'" class="btn btn-mini btn-success row_edit"><?=lang('edit')?></a>&nbsp;<button class="btn btn-mini btn-danger row_delete" data="'+r.id+'"><?=lang('delete')?></button></td>'+
                              '</tr>';
                       }
                       $('#table tbody').html(str);
					   
                   }
               }
            });
        }
		$('#table_paginate a').live('click',function(e){
			var p = $(this).attr('data');
			if(p!=null){
				page=p;
				load_table();
			}
		});
        $('.row_delete').live('click',function(e){
            if(confirm('<?=lang('delete_confirm')?>'))
            {
                $.ajax({
                   url: '<?=url_create('admin','catalogue','delete')?>',
                   type: 'post' ,
                   dataType: 'json',
                   data:{id: $(this).attr('data')},
                   success:function(o)
                   {
                       if(o.state == 'success')
                           $('#row_'+o.id).fadeOut(500);
                       else
                           $.jGrowl(o.message, {
                               header: o.title,
                               theme: "notification_styled_"+o.state 
                           });
                   }
                });
             }
        });
        
        $('.row_edit').live('click',function(e){
			$('#modal').attr('flag','edit');
			$('.modal-form [name="id"]').val($(this).attr('data'));
            $.ajax({
                url: '<?=url_create('admin','catalogue','detail')?>',
                dataType: 'json',
                data: {id: $(this).attr('data')},
                success: function(o){
                    if(o.state=='success'){
                        
						// Ghi du lieu
						var str='<option value="0"><?=lang('none')?></option>';
						for(var i in o.data.parents){
							r=o.data.parents[i];
							str+='<option value="'+r.id+'">'+r.pre+r.name+'</option>';
						}
						$('.modal-form [name="p_id"]').html(str);
						$('.modal-form [name="index"]').attr('value',o.data.index);
						$('.modal-form [name="p_id"]').val(o.data.p_id);
						$('.modal-form [name="type"]').val(o.data.type);
						$('.modal-form [name="active"]').attr('checked',o.data.active==1);
						$('.modal-form [name="home"]').attr('checked',o.data.home==1);
						$('.modal-form [name="main"]').attr('checked',o.data.main==1);
						for(var i in o.data.info)
						{
							for(var j in o.data.info[i])
								$('.modal [name="info['+o.data.info[i].lang_id+']['+j+']"]').val(o.data.info[i][j]);
						}
						
						// Gan lai tieu de 
						$('#modal_title').html('<?=lang('permission_update')?>');
                        $('#modal_toggle').click();
						
                        
                    }
                    else
                        $.jGrowl(o.message, {
                            header: o.title,
                            theme:"notification_styled_"+data.state 
                        });
                }
            })
        });
        
		$('.data_create').live('click',function(e){
			$('#modal').attr('flag','create');		
			// Reset field
			$('#name').attr('value','');
			$('#permission').attr('value','');
			$('#description').val('');
			$.ajax({
				url: '<?=url_create('admin','catalogue','read')?>',
				dataType: 'json',
				success: function(o)
				{
					if(o.state=='success'){
						var str='<option value="0"><?=lang('none')?></option>';
						for(var i in o.data)
						{
							r=o.data[i];
							str+='<option value="'+r.id+'">'+r.pre+r.name+'</option>';
						}
						
						$('.modal-form [name="p_id"]').html(str);
					}
				}
			})
			// Gan tieu de modal
			$('#modal_title').html('<?=lang('permission_create')?>');
			$('#modal_toggle').click();
		});
		
		$('.data_update').live('click',function(e){
			$.ajax({
				url: '<?=url_create('admin','catalogue','update_all')?>',
				dataType: 'json',
				success: function(o){
					if(o.state=='success'){
						load_table();
						$.jGrowl(o.message, {
							header: o.title,
							theme:"notification_styled_"+o.state 
						});
					}
					else{
						alert(o.message);
					}
						
				}
			})
		})
		$('#modal_ok').live('click',function(e){
			$('.modal-form').submit();
		});
        $('.modal-form').submit(function(e){
			var flag = $('#modal').attr('flag');

			$.ajax({
				url: flag=='create'?'<?=url_create('admin','catalogue','create')?>':'<?=url_create('admin','catalogue','update')?>',
				dataType: 'json',
				type: 'post',
				data: $(this).serialize(),
//				data: {
//					id: $('#modal').attr('data_id'),
//					name: $('#name').val(),
//					p_id: $('#p_id').val(),
//					description: $('#description').val(),
//					index: $('#index').val()
//				},
				success: function(o){
					if(o.state=='success'){
						load_table();
						$('#modal_toggle').click();
						$.jGrowl(o.message, {
							header: o.title,
							theme:"notification_styled_"+o.state 
						});
					}else{
						alert(o.message);
					}
					
				}
			});
            return false;
        });
		
        $('#modal_cancel').live('click',function(e){
            $('#modal_toggle').click();
        });
        $(document).ready(load_table());
    </script>
    